<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
            <el-form-item label="标题" prop="title">
                <el-input v-model="queryParams.title" placeholder="请输入标题" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                    v-hasPermi="['business:commission:add']">新增</el-button>
            </el-col>

            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table @selection-change="handleSelectionChange" fit v-loading="loading" border :data="dataList">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="序号" type="index" />
            <el-table-column label="标题" prop="title" :show-overflow-tooltip="true">
            </el-table-column>
            <el-table-column label="类型" prop="userName" :show-overflow-tooltip="true">
                <template slot-scope="scope">
                    {{ list[Number(scope.row.fromType)].title
                    }}
                </template>
            </el-table-column>
            <!-- <el-table-column align="center" label="发布时间" prop="createTime" /> -->
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200" fixed="right">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-view" v-hasPermi="['business:commission:info']"
                        @click="handleDetail(scope.row)">详情</el-button>
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                        v-hasPermi="['business:commission:edit']">修改</el-button>
                    <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                        v-hasPermi="['business:commission:remove']">删除</el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
            @pagination="getList" />
        <!-- 添加或修改公司公告对话框 -->
        <el-dialog title="委托检测服务" :visible.sync="open" width="800px" >
            <el-form ref="form" :model="form" :rules="rules" label-width="80px" :disabled="detailDisabled">
                <el-row>
                    <el-col :span="24">
                        <el-form-item label="标题" prop="title">
                            <el-input v-model="form.title" placeholder="请输入标题" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="类型" prop="fromType">
                            <el-select v-model="form.fromType" placeholder="文件类型" clearable style="width: 240px">
                                <el-option label="委托流程" value="1" />
                                <el-option label="建设资质指南" value="2" />
                                <el-option label="交通资质指南" value="3" />
                                <el-option label="水运资质指南" value="4" />
                                <el-option label="材料类附页" value="5" />
                                <el-option label="工程实体类附页" value="6" />
                                <el-option label="说明" value="7" />
                                <el-option label="建设收费标准" value="8" />
                                <el-option label="交通收费标准" value="9" />
                                <el-option label="其他收费标准" value="10" />
                                <el-option label="报告时效承诺" value="11" />
                                <el-option label="材料固定页" value="12" />
                                <el-option label="工程实体固定页" value="13" />

                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row>
                    <el-col :span="24">
                        <el-form-item label="文件内容">
                            <editor v-if="open" placeholder="请输入公告内容" v-model="form.content" :min-height="500" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                <el-col :span="20">
                    <el-form-item label="文件路径" prop="content">
                        <FileUpload :limit="1" :fileType="fileType" v-model="form.url" @handleUploadSuccess="endUpload"></FileUpload>
                    </el-form-item>
                </el-col>
            </el-row>
                <!-- <el-row>
                    <el-col :span="12">
                        <el-form-item label="是否显示" prop="status">
                            <el-switch v-model="form.status" active-value="1" inactive-value="0"></el-switch>
                        </el-form-item>
                    </el-col>
                </el-row> -->
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm" :disabled="detailDisabled">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
        <!-- <detail :detailOPen.sync="detailOPen" :rowDetail="rowDetail" @cancel="cancel"></detail> -->
    </div>
</template>
  
<script>
// import detail from '../textsFile/detail'
import {
    pageList,
    advOrderAttachmentDel,
    advOrderAttachmentAdd,
    advOrderAttachmentEdit,
    advOrderAttachmentInfo,
} from "@/api/business/commission.js";
import { userSelect, deptTreeSelect } from "@/api/system/user.js";
export default {
    components: {
        // detail,
    },
    name: "project",
    dicts: ["sys_comp_fee_status", "sys_fee_type"],

    data() {
        return {
            detailDisabled:false,
            list:[
                {
                    title:''
                },
                {
                    title: "委托流程",
                    type: 1,
                },
                {
                    title: "建设资质指南",
                    type: 2,
                },
                {
                    title: "交通资质指南",
                    type: 3,
                },
                {
                    title: "水运资质指南",
                    type: 4,
                },
                {
                    title: "材料类附页",
                    type: 5,
                },
                {
                    title: "工程实体类附页",
                    type: 6,
                },
                {
                    title: "说明 ",
                    type: 7,
                },
                {
                    title: "建设收费标准",
                    type: 8,
                },
                {
                    title: "交通收费标准",
                    type: 9,
                },
                {
                    title: "其他收费标准",
                    type: 10,
                },
                {
                    title: "报告时效承诺",
                    type: 11,
                },
                {
                    title: "材料固定页",
                    type: 12,
                },
                {
                    title: "工程实体固定页",
                    type: 13,
                },
            ],
            fileType: ["doc","docx", "xls","xlsx", "ppt", "txt", "pdf", "png", "jpge", "jpg",'fbx','pptx'],
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            dataList: [],
            // 遮罩层
            loading: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                ipAddress: this.$VUE_APP_IMG_API
            },
            rowDetail: {},
            form: {
                // status: 0,
                type: 1,
            },
            detailOPen: false,
            open: false,
            // 表单校验
            rules: {
                title: [
                    { required: true, message: "标题不能为空", trigger: "blur" },
                ],
                fromType: [
                    { required: true, message: "类型不能为空", trigger: "change" },
                ],
                content: [
                    { required: true, message: "内容不能为空", trigger: "blur" },
                ],
                // status: [
                //     { required: false, message: "类型不能为空", trigger: "change" },
                // ],
            },
            baseUrl: this.$VUE_APP_IMG_API,
        };
    },
    created() {
        this.getList();
    },
    methods: {
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map((item) => item.advOrderAttachmentId);
            this.single = selection.length != 1;
            this.multiple = !selection.length;
        },

        /** 修改按钮操作 */
        handleUpdate(row) {
            this.detailDisabled = false;
            this.open = true;
            this.form = row
        },
        handleDetail(row) {
            console.log(row);
            this.detailDisabled = true;
            this.open = true;
            this.form = row
            // let obj = {
            //     advOrderAttachmentId: row.advOrderAttachmentId,
            //     ipAddress: this.$VUE_APP_IMG_API
            // }
            // advOrderAttachmentInfo(obj).then((res) => {
            //     this.rowDetail = res.data;

            // });
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            const configId = row.advOrderAttachmentId || this.ids;
            this.$modal
                .confirm('是否确认删除此条数据？')
                .then(function () {
                    return advOrderAttachmentDel(configId);
                })
                .then(() => {
                    this.getList();
                    this.$modal.msgSuccess("删除成功");
                })
                .catch(() => { });
        },
        cancel() {
            this.open = false;
            this.detailOPen = false;
        },
        handleAdd() {
            // this.$router.push("./textsFileAdd");
            this.form={}
            this.open = true;
            this.detailDisabled = false
        },
        endUpload(e){
            console.log(e);
            this.form.fileType = e.data.fileSuffix
            if(this.form.fromType == '5' ){
                this.form.title = e.data.fileName
            }
        },
        /** 提交按钮 */
        submitForm() {
            this.$refs["form"].validate((valid) => {
                if (valid) {
                    if (this.form.advOrderAttachmentId != undefined) {
                        this.form.ipAddress=this.$VUE_APP_IMG_API
                        advOrderAttachmentEdit(this.form).then((response) => {
                            this.$modal.msgSuccess("修改成功");
                            this.open = false;
                            this.getList();
                        });
                    } else {
                        // this.form.busType = 2;
                        advOrderAttachmentAdd(this.form).then((response) => {
                            this.$modal.msgSuccess("新增成功");
                            this.open = false;
                            this.getList();
                        });
                    }
                }
            });
        },
        /** 查询列表 */
        getList() {
            this.loading = true;
            pageList(this.queryParams).then((response) => {
                this.dataList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        /** 查询部门下拉树结构 */
        getDeptTree() {
            deptTreeSelect().then((response) => {
                this.deptOptions = response.data;
            });
        },

        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
    },
};
</script>
<style lang="scss" scoped>
::v-deep .el-dialog__body {
    img {
        width: 100%;
    }
}
</style>
  